package com.whu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whu.aircraft.FlightTask;
import com.whu.aircraft.TrackInfo;
import com.whu.dao.interfaces.FlightTaskDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class FlightTaskService {
    FlightTaskDao flightTaskDao;
    @Autowired
    public FlightTaskService(FlightTaskDao flightTaskDao) {
        this.flightTaskDao = flightTaskDao;
    }

    public IPage<FlightTask> listByNameWithPage(String name,int page,int num){
        name = name.trim();
        Page<FlightTask> pager = new Page<>(page,num);
        QueryWrapper<FlightTask> queryWrapper = new QueryWrapper<>();
        boolean byName = true;
        if(name.equals("")){
            byName = false;
        }
        queryWrapper.like(byName,"flight_task_name",name);
        IPage<FlightTask> iPage = flightTaskDao.selectPage(pager,queryWrapper);
        return iPage;
    }
    public ArrayList<FlightTask> listAllTask(){
        QueryWrapper<FlightTask> wrapper = new QueryWrapper<>();
        return (ArrayList<FlightTask>) flightTaskDao.selectList(wrapper);
    }

    public IPage<FlightTask> listWithPage(int page,int num){
        Page<FlightTask> pager = new Page<>(page,num);
        QueryWrapper<FlightTask> queryWrapper = new QueryWrapper<>();
        IPage<FlightTask> iPage = flightTaskDao.selectPage(pager,queryWrapper);
        return iPage;
    }

    public int deleteTaskById(Long deletedId){
        return flightTaskDao.deleteById(deletedId);
    }
     public int updateTaskById(FlightTask task){
        return flightTaskDao.updateById(task);
     }
     public int insert(FlightTask task){
        return flightTaskDao.insert(task);
     }
}
